﻿using System;
using System.Configuration;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KPIS.DBM;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.IDAL;

namespace KPIS.GERP.GHRMS.DAL
{
    public sealed class HisGoodNessDAL
    {
        IDBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);

        public HisGoodNessDAL()
        {
        }
        public DataSet LoadHisGoodNess(Nullable<int> Sequence, Nullable<int> EmpSequence)
        {
            string strSQL;
            
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(3);

                dbManager.AddParameters(0, "@ActiveRecord", SystemInfo._ActiveRecordStatus);
                dbManager.AddParameters(1, "@Sequence", Sequence);
                dbManager.AddParameters(2, "@EmpSequence", EmpSequence);

                DataSet ds = null;

                strSQL = "SELECT gn.GOOD_NESS_SEQ, gn.EMP_SEQ, gn.GOOD_NESS_DESCR, gn.GOOD_NESS_DATE"
                        + ", gn.REMARKS, gn.RECORD_STATUS, gn.CREATED_BY, gn.UPDATED_BY, gn.CREATED_WHEN"
                    + " FROM HRM_PS_EMP_GOODNESS gn"
                    + " WHERE gn.RECORD_STATUS = @ActiveRecord"
                    + (Sequence.HasValue ? " AND gn.GOOD_NESS_SEQ = @Sequence" : "")
                    + (EmpSequence.HasValue ? " AND gn.EMP_SEQ = @EmpSequence" : "");
                ds = dbManager.ExecuteDataSet(CommandType.Text, strSQL);

                return ds;
            }
            catch
            {
                return null;
                throw;
            }
            finally
            {
                dbManager.CloseReader();
                dbManager.Dispose();
            }
        }
    }
}
